<?php 
/**
 * alltosun.com admin_widget
 * ============================================================================
 * 版权所有 (C) 2009-2011 北京互动阳光科技有限公司，并保留所有权利。
 * 网站地址: http://www.alltosun.com
 * ----------------------------------------------------------------------------
 * 许可声明：这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
 * ============================================================================
 * $Author: 高昂 (gaoa@alltosun.com) $
 * $Date: 2016-3-9 下午3:21:53 $
 * $Id: $
 */

class admin_widget
{
    /**
     * 
     * 合伙人相关统计信息
1.合伙人数量：（要求排除不统计测试账号实际目前就6个）
2.今日新增：多少人增长率多少
3.成交订单数/已收到款项：:订单数量/（成交金额）多少元 (确认收款)
4.已成功出货：多少箱 (发货)
5.待收款订单/等待收款项：订单数量/（未成交金额）多少元
6.等待发货：多少箱 (只要提交订单就算是)
7.合伙人总库存：多少箱
8.合伙人总员工：多少人 (市场人员的总数量)


终端门店相关统计信息
1.终端门店总数量
2.今日新增：多少门店增长率多少
3.已进货门店数量：(必须是确认收货的门店)
4.未进货门店数量：(其他)
5.门店订单总量：(所有订单)
6.今日新增订单量：(统计处在配送中的订单)
     */
    public function get_admin_data_list()
    {
        $admin_data_list = array();
        // 总的用户数
        $admin_data_list['all_user_num'] = user_helper::get_user_num_by_role_id();
        // 经销商相关数据
        // 经销商数量
        $admin_data_list['dealer_num'] = user_helper::get_user_num_by_role_id(user_config::AGENCY);
        // 今日新增：多少人增长率多少
        $today_add_dealer_num = user_helper::get_user_num_by_role_id(user_config::AGENCY, array('`add_time` LIKE '=>date('Y-m-d').'%'));
        $before_dealer_num = user_helper::get_user_num_by_role_id(user_config::AGENCY, array('`add_time` < '=>date('Y-m-d').' 00:00:00'));
        $admin_data_list['today_add_dealer_num'] = $today_add_dealer_num;
        $admin_data_list['dealer_growth_rate'] = round(($today_add_dealer_num / $before_dealer_num) * 100, 2);
        // 成交订单数/已收到款项
        $admin_data_list['dealer_order_num'] = order_helper::get_order_num_by_progress(array(3, 5, 10), 1, array('is_enable'=>1, 'status'=>1));
        $admin_data_list['dealer_order_money'] = order_helper::get_order_money_by_progress(array(3, 5, 10), 1,  array('is_enable'=>1, 'status'=>1));
        
        // 已成功出货：多少箱 (总部向合伙人发货)
        $admin_data_list['delivery_goods_num'] = order_helper::get_order_goods_num(array(5, 10), 1, array('is_enable'=>1, 'status'=>1));
        
        // 待收款订单/等待收款项：订单数量/（未成交金额）多少元
        $admin_data_list['prepare_dealer_order_num'] = order_helper::get_order_num_by_progress(1, 1, array('is_enable'=>1, 'status'=>1));
        $admin_data_list['prepare_dealer_order_money'] = order_helper::get_order_money_by_progress(1, 1, array('is_enable'=>1, 'status'=>1));
        
        // 等待发货：多少箱 (只要提交订单就算是)
        $admin_data_list['prepare_delivery_order_num'] = order_helper::get_order_goods_num(array(1, 3), 1, array('is_enable'=>1, 'status'=>1));

        // 合伙人总库存：多少箱
        $dealer_ids = user_helper::get_role_user_ids(user_config::AGENCY, '' , array('is_enable'=>1));
        // $filter_dealer_ids = user_helper::get_user_ids_by_mobile(user_config::$test_user_mobile);
        // $dealer_ids = array_diff($dealer_ids, $filter_dealer_ids);
        $admin_data_list['all_dealer_stock'] = dealers_helper::get_dealer_stock($dealer_ids);
        // 合伙人总员工：多少人 (市场人员的总数量)
        $store_list = store_helper::get_store_list_by_dealer_id($dealer_ids, array('is_enable'=>1, 'is_delete'=>1 ));
        $marketing_ids = array();
        if ($store_list) {
            foreach ($store_list as $k=>$v) {
                if (!in_array($v['marketing_id'], $marketing_ids)) {
                    array_push($marketing_ids, $v['marketing_id']);
                }
            }
        }
        $admin_data_list['marketing_num'] = count($marketing_ids);
        
        // 市场人员信息暂时不统计
//       市场人员相关数据
//         $admin_marketing_num = user_helper::get_format_user_num_by_role_id(user_config::MARKETING);
//         $admin_marketing_percent = 100 * round($admin_marketing_num / $admin_total_user_num, 4) . '%';
        // 统计市场人员处理的订单数
        // $admin_marketing_order_num = order_helper::get_marketing_order_num();
        
        // 终端店铺相关数据(分店)
        $admin_data_list['store_num'] = user_helper::get_user_num_by_role_id(user_config::STORE_MANAGER);
        // 今日新增：多少门店增长率多少 
        $today_add_store_num = user_helper::get_user_num_by_role_id(user_config::STORE_MANAGER, array('`add_time` LIKE '=>date('Y-m-d').'%'));
        $admin_data_list['today_add_store_num'] = $today_add_store_num;
        $before_store_num = user_helper::get_user_num_by_role_id(user_config::STORE_MANAGER, array('`add_time` < '=>date('Y-m-d').' 00:00:00'));
        $admin_data_list['store_growth_rate'] = round($today_add_store_num / $before_store_num * 100, 2);
        // $admin_store_order_num = order_helper::get_order_num_by_progress(10, 5);
        // 已进货门店数量：(必须是确认收货的门店)
        $admin_data_list['is_stock_store_num'] = user_helper::get_user_num_by_role_id(user_config::STORE_MANAGER, array('`score` > '=>0));
        // 未进货门店数量：(其他)
        $admin_data_list['not_stock_store_num'] = $admin_data_list['store_num'] - $admin_data_list['is_stock_store_num'];
        // 门店订单总量：(所有订单)
        $admin_data_list['store_order_num'] = order_helper::get_order_num_by_progress(array(1, 3, 5, 10, 15), 5, array('status'=>1, 'is_enable'=>1));
        // 今日新增订单量：(统计处在配送中的订单,不会撤销的订单)
        $admin_data_list['store_new_order_num'] = order_helper::get_order_num_by_progress(array(5, 10), 5, array('status'=>1, 'is_enable'=>1));
        return $admin_data_list;
    }
    
    /**
     * 按照时间返回对应的日，周，月，统计用
     * @param unknown_type $type
     * @param unknown_type $time
     * @return string
     */
    private function get_date($type, $time = '')
    {
        if (!$time)  $time = time();
    
        if ($type == 'day') {
            $date = date('Y-m-d', $time);
        } else if ($type == 'week') {
            // 第几周
            $date = strftime('%Y%W', $time);
        } else if ($type == 'month') {
            $date = date('Ym', $time);
        }
        return $date;
    }
    
    
    
}

?>